package com.gk.panda.apis.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gk.panda.apis.entity.TransectManager.vo.PointDataVo;
import com.gk.panda.apis.mapper.TransectPointDataMapper;
import com.gk.panda.apis.service.TransectPointDataService;
import com.gk.panda.pojo.TransectPointData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName: TransectPointDataServiceImpl
 * @Description: 样线经纬度
 * @author: Sir.yang
 * @date: 2022/11/10 15:01
 * @version: 1.0
 **/
@Service
@Slf4j
public class TransectPointDataServiceImpl extends ServiceImpl<TransectPointDataMapper, TransectPointData> implements TransectPointDataService {


    /**
     * @description: 根据样线ID获取经纬度数据
     * @param: [transectId]
     * @return: java.util.List<com.gk.panda.apis.entity.TransectManager.vo.PointDataVo>
     * @date: 2022/11/10 15:04
     * @version: 1.0
     **/
    @Override
    public List<PointDataVo> getPointDataByTransectId(Integer transectId) {
        QueryWrapper<TransectPointData> wrapper = new QueryWrapper<>();
        wrapper.eq("transect_id", transectId);
        List<TransectPointData> dataList = baseMapper.selectList(wrapper);
        List<PointDataVo> vos = new ArrayList<>();
        if(!CollectionUtils.isEmpty(dataList)){
            vos = dataList.stream().map(data ->{
                PointDataVo vo = new PointDataVo();
                BeanUtils.copyProperties(data, vo);
                return vo;
            }).collect(Collectors.toList());
        }
        return vos;
    }

    /**
     * @description: 保存样线经纬度数据
     * @param: [pointDatas]
     * @return: java.lang.Integer
     * @date: 2022/11/10 15:04
     * @version: 1.0
     **/
    @Override
    @Transactional
    public Integer saveTransectPointData(List<TransectPointData> pointDatas) {
        return baseMapper.insertList(pointDatas);
    }
}
